import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBHelper/YBColor/YBColor.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBHelper/YBImageStyle/YBImageStyle.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBHelper/YBTextStyle/YBTextStyle.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBHelper/yb_chinese_text/yb_chinese_text.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBJsonToModel/YBMineModel/YBMineGongDanModel.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBModule/YBMineModule/YBMineProvider/YBMineProvider.dart';

import 'YBMyGongDanSubPage.dart';

enum YBMyGongDanType {
  YBMYGongDanType_MygongdanList,
  YBMYGongDanType_DaiJieDanInfo,
  YBMYGongDanType_YiJieDanInfo
}


class YBMyGongDanPage extends StatelessWidget {

  final YBMyGongDanType type;

  const YBMyGongDanPage({Key key, this.type}) : super(key: key);


  @override
  Widget build(BuildContext context) {

    String types;
    String _titleStr;
    if (type == YBMyGongDanType.YBMYGongDanType_MygongdanList) {
       types = '';
       _titleStr = YBChineseText.mineMydeGongdanTitle;
    } else if (type == YBMyGongDanType.YBMYGongDanType_DaiJieDanInfo) {
       types = '0';
       _titleStr = YBChineseText.minedaiJieDanTitle;
    } else if (type == YBMyGongDanType.YBMYGongDanType_YiJieDanInfo) {
       types = '1';
       _titleStr = YBChineseText.mineYiJieDanTitle;
    }

    return Container(
        child: DefaultTabController(
          length: 3,
          child:Scaffold(
            appBar: AppBar(
              elevation: 0,
              title: Text(
                _titleStr??"",
               style: YBTextStyle.TextStyle30313320Medium
              ),
              bottom: TabBar(
                  indicatorSize: TabBarIndicatorSize.label,
                  unselectedLabelColor: YBColor.color1B1C1F,
                  labelColor: YBColor.commonThemeColor,
                  indicatorColor: YBColor.commonThemeColor,
                  tabs: [
                    Tab(text: YBChineseText.homeTextShangWuMiShuTitle,),
                    Tab(text: YBChineseText.mineFaLvZiXunTitle,),
                    Tab(text: YBChineseText.mineFaLvGuWenTitle,),
                  ]
              ),
            ),
            body:TabBarView(
              children: [
                Container(
                  child: ChangeNotifierProvider(
                    create: (context) => YBBaseMineProvider()..getGongDanInfoData(1, types, "business_secretary"),
                    child: Consumer<YBBaseMineProvider>(
                        builder: (context,mineDataList,child){
                          return SmartRefresher(
                            controller:mineDataList.easyRefresh,
                            onLoading: () async {
                              mineDataList.loadData(types,"business_secretary");
                            },
                            onRefresh: () async {
                              mineDataList.refreshData(types,"business_secretary");
                            },
                            enablePullDown: true,
                            enablePullUp: true,
                            child: CustomScrollView(
                              slivers: [
                                SliverList(
                                  delegate: SliverChildBuilderDelegate((_,int index){
                                    YBMineGongDanModel yiJiModel = mineDataList.gongDanModelList[index];
                                    return YBMyGongDanSubPage(contentStr: yiJiModel.requestTag,addressStr: yiJiModel.address,shengYuStr:yiJiModel.firstMaxGetNumber.toString(),timeStr: yiJiModel.createTime,sysCodeStr: yiJiModel.sysCode,requestCodeStr: yiJiModel.requestCode,);
                                  },
                                    childCount: mineDataList.gongDanModelList.length,
                                  ),
                                ),
                              ],
                            ),
                          );
                        }
                    ),
                  ),
                ),
                Container(
                  child: ChangeNotifierProvider(
                    create:(context) => YBBaseMineProvider()..getGongDanInfoData(1, types, "administrative_secretary"),
                    child: Consumer<YBBaseMineProvider>(
                        builder: (context,mineList,child){
                          return SmartRefresher(
                            controller:mineList.easyRefresh,
                            onRefresh: () async {
                              mineList.refreshData(types, "administrative_secretary");
                            },
                            onLoading: () async {
                              mineList.loadData(types, "administrative_secretary");
                            },
                            enablePullUp: true,
                            enablePullDown: true,
                            child: CustomScrollView(
                              slivers: [
                                SliverList(
                                  delegate: SliverChildBuilderDelegate((_,int index){
                                    YBMineGongDanModel yiJiModel = mineList.gongDanModelList[index];
                                    return YBMyGongDanSubPage(contentStr: yiJiModel.requestTag,addressStr: yiJiModel.address,shengYuStr:yiJiModel.firstMaxGetNumber.toString(),timeStr: yiJiModel.createTime,sysCodeStr: yiJiModel.sysCode,requestCodeStr: yiJiModel.requestCode,);
                                  },
                                    childCount: mineList.gongDanModelList.length,
                                  ),
                                ),
                              ],
                            ),
                          );
                        }
                    ),
                  ),
                ),
                Container(
                  child: ChangeNotifierProvider(
                    create: (context) => YBBaseMineProvider()..getGongDanInfoData(1, types, "lawyer_secretary"),
                    child: Consumer<YBBaseMineProvider>(
                      builder: (context,mineBaseList,child){

                        return SmartRefresher(
                          controller:mineBaseList.easyRefresh,
                          onLoading: () async {
                            mineBaseList.loadData(types, "lawyer_secretary");
                          },
                          onRefresh: () async {
                            mineBaseList.refreshData(types, "lawyer_secretary");
                          },
                          enablePullDown: true,
                          enablePullUp: true,
                          child: CustomScrollView(
                            slivers: [
                              SliverList(
                                delegate: SliverChildBuilderDelegate((_,int index){
                                  YBMineGongDanModel yijiModel = mineBaseList.gongDanModelList[index];
                                  print("----${yijiModel.requestCode} ----- ${yijiModel.sysCode}");
                                  return YBMyGongDanSubPage(contentStr: yijiModel.requestTag,addressStr: yijiModel.address,shengYuStr:yijiModel.firstMaxGetNumber.toString(),timeStr: yijiModel.createTime,sysCodeStr: yijiModel.sysCode,requestCodeStr: yijiModel.requestCode,);
                                },
                                  childCount: mineBaseList.gongDanModelList.length,
                                ),
                              ),
                            ],
                          ),
                        );
                      },
                    ),
                  ),
                ),
              ],
            ),
          ),
        ),
    );
  }
}
